class ReposWatching
  attr_accessor :github

  def initialize(github)
    @github = github
  end

  def listWatchers(repo, user=nil)
    username = user == nil ? @github.username : user
    @github.get('repos/%s/%s/watchers' % [username, repo])
  end

  def listWatchedRepos(user=nil)
    url = (user != nil and user != @github.username) ?
        'users/%s/watched' % user : 'user/watched'
    @github.get(url)
  end

  def checkIfWatching(repo, user=nil)
    username = user == nil ? @github.username : user
    @github.get('user/watched/%s/%s' % [username, repo])
  end

  def watchRepo(repo, user=nil)
    username = user == nil ? @github.username : user
    @github.put('user/watched/%s/%s' % [username, repo])
  end

  def stopWatching(repo, user=nil)
    username = user == nil ? @github.username : user
    @github.delete('user/watched/%s/%s' % [username, repo])
  end
end